﻿Imports CupsApp.Service

Partial Public Class manage_clients
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            lvlMsg.Text = ""
        End If

    End Sub

    Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand
        lvlMsg.Text = ""

        Dim context As New HttpContextWrapper(HttpContext.Current)
        Dim service As CupsDomainService = DomainServicesFactory.CreateDomainService(context)
        If (e.CommandName = "Enable") Then
            If (service.EnableClient(e.CommandArgument)) Then
                lvlMsg.Text = String.Format("Client: {0} enabled", e.CommandArgument)
            Else
                lvlMsg.ForeColor = Drawing.Color.Red
                lvlMsg.Text = String.Format("Failed to enable Client : {0}", e.CommandArgument)
            End If
        ElseIf (e.CommandName = "Deleted") Then
            lvlMsg.Text = String.Format("Client: {0} was deleted successfully.", e.CommandArgument)
        End If
    End Sub
End Class